<template>
  <div class='q-pa-md'>
    <div class='row'>
      <div class='col'>
        <q-input label='公司ID' filled v-model='companyId'/>
      </div>
      <div class='col'>
        <q-btn style="margin-right: 20px;" color="white" text-color="black" label="确认" @click='getInformation'/>
        <q-btn :title="canUseBatch==2?'当前登录已使用一次批量':''" v-if="canUseBatch!=0" :disable="canUseBatch!=1" color="white" text-color="black" label="批量" @click='batch'/>
      </div>
      <div class='col'>
        
      </div>
      <div class='col'></div>
    </div>
    <div class='row'>
      <div class="col ">
        <q-select
          filled
          v-model="entity"
          :options="EntityArr"
          option-value="entityCode"
          option-label="codeName"
          label="主体"
          emit-value
          map-options
          style="min-width: 250px; max-width: 300px"
          @update:model-value='selectFn()'
        />
      </div>
      <div class="col">
        <q-select
          filled
          v-model="entityChild"
          :options="EntityChildArr"
          option-value="entityType"
          option-label="typeName"
          label="当事子主体"
          emit-value
          map-options
          style="min-width: 250px; max-width: 300px"
        />
      </div>
      <div class="col">
        <q-select
          filled
          v-model="AstridTasksValue"
          :options="AstridTasks"
          option-value="objectCodeType"
          option-label="objectCodeName"
          label="权限事项"
          emit-value
          map-options
          style="min-width: 250px; max-width: 300px"
        />
      </div>
    </div>

    <div class='row'>
      <div>
        <div class='inner'>当前场景1：</div>
      </div>
      <div class='col'>
        <q-select
          filled
          v-model="SceneEntity"
          :options="SceneEnitityArr"
          option-value="entityCode"
          option-label="codeName"
          label="场景主体"
          emit-value
          map-options
          @update:model-value='selectSceneFn()'
        />
      </div>
      <div class='col'>
        <q-select
          filled
          v-model="SceneEntityChild"
          :options="SceneEntityChildArr"
          option-value="entityType"
          option-label="typeName"
          label="场景子主体"
          emit-value
          map-options
          @update:model-value='selectSceneChildFn()'
        />
      </div>
      <div class='col'>
        <q-select
          filled
          v-model="Event"
          :options="SceneEntityEventArr"
          option-value="entityType"
          option-label="eventName"
          label="场景主体事件"
          emit-value
          map-options
        />
      </div>
      <div class='col'>
        <q-select
          filled
          v-model="Property"
          :options="SceneEntityPropertyArr"
          option-value="propertyEnglish"
          option-label="propertyChinese"
          label="场景主体属性"
          emit-value
          map-options
        />
      </div>
      <div class='col'>
<!--        <q-btn color="primary" label="添加" />-->
      </div>
    </div>

<!--场景2-->
    <div class='row'>
      <div>
        <div class='inner'>当前场景2：</div>
      </div>
      <div class='col'>
        <q-select
          filled
          v-model="SceneEntity1"
          :options="SceneEnitityArr"
          option-value="entityCode"
          option-label="codeName"
          label="场景主体"
          emit-value
          map-options
          @update:model-value='selectSceneFn1()'/>
      </div>
      <div class='col'>
        <q-select
          filled
          v-model="SceneEntityChild1"
          :options="SceneEntityChildArr1"
          option-value="entityType"
          option-label="typeName"
          label="场景子主体"
          emit-value
          map-options
          @update:model-value='selectSceneChildFn1()'/>
      </div>
      <div class='col'>
        <q-select
          filled
          v-model="Event1"
          :options="SceneEntityEventArr1"
          option-value="entityType"
          option-label="eventName"
          label="场景主体事件"
          emit-value
          map-options/>
      </div>
      <div class='col'>
        <q-select
          filled
          v-model="Property1"
          :options="SceneEntityPropertyArr1"
          option-value="roleType"
          option-label="roleName"
          label="场景主体属性"
          emit-value
          map-options/>
      </div>
      <div class='col'></div>
    </div>
<!--场景3-->
    <div class='row'>
      <div>
        <div class='inner'>当前场景3：</div>
      </div>
      <div class='col'>
        <q-select
          filled
          v-model="SceneEntity2"
          :options="SceneEnitityArr"
          option-value="entityCode"
          option-label="codeName"
          label="场景主体"
          emit-value
          map-options
          @update:model-value='selectSceneFn2()'/>
      </div>
      <div class='col'>
        <q-select
          filled
          v-model="SceneEntityChild2"
          :options="SceneEntityChildArr2"
          option-value="entityType"
          option-label="typeName"
          label="场景子主体"
          emit-value
          map-options
          @update:model-value='selectSceneChildFn2()'/>
      </div>
      <div class='col'>
        <q-select
          filled
          v-model="Event2"
          :options="SceneEntityEventArr2"
          option-value="entityType"
          option-label="eventName"
          label="场景主体事件"
          emit-value
          map-options/>
      </div>
      <div class='col'>
        <q-select
          filled
          v-model="Property2"
          :options="SceneEntityPropertyArr2"
          option-value="roleType"
          option-label="roleName"
          label="场景主体属性"
          emit-value
          map-options/>
      </div>
      <div class='col'></div>
    </div>

    <hr>

    <div class="q-pa-md q-gutter-sm">
      <q-btn class="btn-fixed-width" color="accent" label="查询" size='md' @click='queryEntityMessage'/>
      <q-btn class="btn-fixed-width" color="accent" label="提交" @click='submitSelectMessage'/>
      <q-btn class="btn-fixed-width" color="accent" label="初始" @click='submitInitMessage'/>
      <q-btn class="btn-fixed-width" color="accent" label="初始1" @click='submitInitMessage1'/>
      <q-btn class="btn-fixed-width" outline color="primary" label="取消" />
    </div>

    <div class='row'>
      <div class='col'>
        <q-chip size="20px">主体</q-chip>
        <div class="q-pa-lg">
          <q-option-group
            v-model="groupEntity"
            :options="EntityPropertyOptions"
            color="green"
            type="checkbox"
          />
        </div>
      </div>
      <div class='col'>
        <q-chip size="20px">子主体</q-chip>
        <div class="q-pa-lg">
          <q-option-group
            v-model="groupChildEntity"
            :options="EntityChildPropertyOptions"
            color="green"
            type="checkbox"
          />
        </div>
      </div>
      <div class='col' v-if='AstridTasksValue !== "301"'>
        <q-chip size="20px">主体属性</q-chip>
        <div class="q-pa-lg">
          <q-option-group
            v-model="group"
            :options="PropertyOptions"
            color="green"
            type="checkbox"
          />
        </div>
      </div>
      <div class='col' v-else>
        <q-chip size="20px">主体属性</q-chip>
        <div class="q-pa-lg">
          <q-option-group
            v-model="Authoritygroup"
            :options="AuthorityPropertyOptions"
            color="green"
            type="checkbox"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script lang='ts'>
import { postRequest, getRequest } from 'src/components/functions'
import { computed, onMounted,watch } from 'vue';
import { reactive,ref } from 'vue'
import { useQuasar } from 'quasar'
import { useStore } from 'src/store';

export default {
  name: 'Permissions.vue',
  setup() {

    const $q = useQuasar()
    let groupEntity = ref([])
    let EntityPropertyOptions = reactive([])
    let groupChildEntity = ref([])
    let EntityChildPropertyOptions = reactive([])
    let mainLabel = ref(null);
    let childLabel = ref(null);
    let group = ref([])
    let Authoritygroup = ref([])
    let AuthorityPropertyOptions = reactive([])
    let PropertyOptions = reactive([]);
    let mainEntity = ref(true);
    let entity = ref(' ')
    let entityChild = ref(' ')
    let SceneEntity = ref(null);
    let SceneEntityChild = ref(null)
    let SceneEntityEventArr = reactive([])
    let SceneEntityPropertyArr = reactive([])
    let Event = ref(null)
    let Property = ref(null)
    let model = ref(null)
    let options = reactive([])
    const store = useStore();
    const userData = store.state.sphinx.userData;
    let AstridTasksValue = ref('')
    let companyId = ref(userData.companyId)

    //当前场景2
    let SceneEntity1 = ref(null)
    let SceneEnitityArr1 = reactive([])
    let SceneEntityChild1 = ref(null)
    let SceneEntityChildArr1 = reactive([])
    let Event1 = ref(null)
    let Event2 =ref(null)
    let Property1 = ref(null)
    let Property2 = ref(null)
    let SceneEntityEventArr1 = reactive([])
    let SceneEntityEventArr2 = reactive([])
    let SceneEntityPropertyArr1 = reactive([])
    let SceneEntityPropertyArr2 = reactive([])
    let swapProperty = []
    async function getInformation() {
      await getCompanyEntity()
      await getObjectType()
      canUseBatch.value++
    }
    function selectSceneFn1() {
      while(SceneEntityChildArr1.length >0){
        SceneEntityChildArr1.pop();
      }
      SceneEnitityArr.forEach((item,index,array)=>{
        if(item.entityCode == SceneEntity1.value){
          item.childArr.forEach((item,index,arr)=>{
            SceneEntityChildArr1.push(JSON.parse(JSON.stringify(item)));
          })
        }

        if(SceneEntity1.value == item.entityCode){
          mainLabel.value = item.codeName;
        }
      })
      //根据主体代码获取主体事件列表
      while(SceneEntityEventArr1.length >0){
        SceneEntityEventArr1.pop();
      }
      while(SceneEntityPropertyArr1.length >0){
        SceneEntityPropertyArr1.pop();
      }
      const reqEventBody = {
        "entityCode":SceneEntity1.value,
        "entityType":null
      }
      postRequest('/channel/channel/getEntityEvent',reqEventBody,(res)=>{
        res.forEach((item,index,arr)=>{
          SceneEntityEventArr1.push(JSON.parse(JSON.stringify(item)))
        })
      })

      //根据主体代码获取主体属性列表
      const reqPropertyBody = {
        "entityCode":SceneEntity1.value,
        "entityType":null
      }
      postRequest('/channel/channel/getEntityProperty',reqPropertyBody,(res)=>{
        res.forEach((item,index,arr)=>{
          SceneEntityPropertyArr1.push(JSON.parse(JSON.stringify(item)));
        })
      })
    }

    function selectSceneChildFn1() {

      SceneEntityChildArr1.forEach((item,index,array)=>{
        if(SceneEntityChild1.value == item.entityType){
          childLabel.value = item.typeName;
        }
      })
      while(SceneEntityEventArr1.length >0){
        SceneEntityEventArr1.pop();
      }
      while(SceneEntityPropertyArr1.length >0){
        SceneEntityPropertyArr1.pop();
      }

      const reqEventBody = {
        "entityCode":SceneEntity1.value,
        "entityType":SceneEntityChild1.value
      }
      postRequest('/channel/channel/getEntityEvent',reqEventBody,(res)=>{
        res.forEach((item,index,arr)=>{
          SceneEntityEventArr1.push(JSON.parse(JSON.stringify(item)))
        })
      })

      const reqPropertyBody = {
       // "groupEntityCode":companyId.value,
        "entityCode":SceneEntity1.value,
        "entityType":SceneEntityChild1.value
      }
      postRequest('/channel/channel/getEntityProperty',reqPropertyBody,(res)=>{
        console.log("resxpa",res);
        if(res.length>0){
          propertyEnglish.value = res[0].propertyEnglish;
          const requestInterface = {
            entityCode: SceneEntity1.value,
            entityType: SceneEntityChild1.value,
            eventCode: "001",
            propertyCode: propertyEnglish.value
          }
          postRequest('channel/channel/getPropertyInterface',requestInterface,(res)=>{
            postRequest(res.data.interfaceEnglish,{companyId:companyId.value},(res)=>{
              res.forEach((item,index,array)=>{
                SceneEntityPropertyArr1.push(JSON.parse(JSON.stringify(item)))
              })
            })
          })
        }
      })
    }

    //当前场景3
    let SceneEntity2 = ref(null)
    let SceneEnitityArr2 = reactive([])
    let SceneEntityChild2 = ref(null)
    let SceneEntityChildArr2 = reactive([])
    function selectSceneFn2() {
      while(SceneEntityChildArr2.length >0){
        SceneEntityChildArr2.pop();
      }
      SceneEnitityArr.forEach((item,index,array)=>{
        if(item.entityCode == SceneEntity2.value){
          item.childArr.forEach((item,index,arr)=>{
            SceneEntityChildArr2.push(JSON.parse(JSON.stringify(item)));
          })
        }

        if(SceneEntity2.value == item.entityCode){
          mainLabel.value = item.codeName;
        }
      })
      //根据主体代码获取主体事件列表
      while(SceneEntityEventArr2.length >0){
        SceneEntityEventArr2.pop();
      }
      while(SceneEntityPropertyArr2.length >0){
        SceneEntityPropertyArr2.pop();
      }
      const reqEventBody = {
        "entityCode":SceneEntity2.value,
        "entityType":null
      }
      postRequest('/channel/channel/getEntityEvent',reqEventBody,(res)=>{
        res.forEach((item,index,arr)=>{
          SceneEntityEventArr2.push(JSON.parse(JSON.stringify(item)))
        })
      })
      //根据主体代码获取主体属性列表
      const reqPropertyBody = {
      // "companyId":companyId.value,
        "entityCode":SceneEntity2.value,
        "entityType":null
      }
      postRequest('/channel/channel/getEntityProperty',reqPropertyBody,(res)=>{
        console.log("resxpa1",res);
        res.forEach((item,index,arr)=>{
          SceneEntityPropertyArr2.push(JSON.parse(JSON.stringify(item)));
        })
      })
    }
    function selectSceneChildFn2() {

      SceneEntityChildArr2.forEach((item,index,array)=>{
        if(SceneEntityChild2.value == item.entityType){
          childLabel.value = item.typeName;
        }
      })
      while(SceneEntityEventArr2.length >0){
        SceneEntityEventArr2.pop();
      }
      while(SceneEntityPropertyArr2.length >0){
        SceneEntityPropertyArr2.pop();
      }

      const reqEventBody = {
        "entityCode":SceneEntity2.value,
        "entityType":SceneEntityChild2.value
      }
      postRequest('/channel/channel/getEntityEvent',reqEventBody,(res)=>{
        res.forEach((item,index,arr)=>{
          SceneEntityEventArr2.push(JSON.parse(JSON.stringify(item)))
        })
      })

      const reqPropertyBody = {
       // "groupEntityCode":companyId.value,
        "entityCode":SceneEntity2.value,
        "entityType":SceneEntityChild2.value
      }
      postRequest('/channel/channel/getEntityProperty',reqPropertyBody,(res)=>{
        console.log("resxpa2",res);
        if(res.length>0){
          propertyEnglish.value = res[0].propertyEnglish;
          const requestInterface = {
            entityCode: SceneEntity2.value,
            entityType: SceneEntityChild2.value,
            eventCode: "001",
            propertyCode: propertyEnglish.value
          }
          postRequest('channel/channel/getPropertyInterface',requestInterface,(res)=>{
            postRequest(res.data.interfaceEnglish,{companyId:companyId.value},(res)=>{
              res.forEach((item,index,array)=>{
                SceneEntityPropertyArr2.push(JSON.parse(JSON.stringify(item)))
              })
            })
          })
        }
      })
    }

    //获取主体列表
    let EntityArr = reactive([])
    let SceneEnitityArr = reactive([])
    function getCompanyEntity() {
      return new Promise<void>((resolve, reject) => {
        const requestBody = {
          companyId: companyId.value
        }
        postRequest('/channel/channel/getCompanyEntity', requestBody, (res) => {
          res.forEach((item, index, arr) => {
            if (item.entityType == '') {
              EntityArr.push(JSON.parse(JSON.stringify(item)))
              SceneEnitityArr.push(JSON.parse(JSON.stringify(item)));
            }
          })
          EntityArr.forEach((item, index, arr) => {
            item.childArr = []
            for (let i = 0; i < res.length; i++) {
              if (res[i].entityCode == item.entityCode && res[i].entityType !== '') {
                item.childArr.push(JSON.parse(JSON.stringify(res[i])))
              }
            }
          })
          SceneEnitityArr.forEach((item, index, arr) => {
            item.childArr = []
            for (let i = 0; i < res.length; i++) {
              if (res[i].entityCode == item.entityCode && res[i].entityType !== '') {
                item.childArr.push(JSON.parse(JSON.stringify(res[i])))
              }
            }
          })
          resolve()
        })
      })

    }

    //选择主体时触发的函数
    let EntityChildArr = reactive([])
    function selectFn() {
      entityChild.value = "";
      while(EntityChildArr.length >0){
        EntityChildArr.pop();
      }
      EntityArr.forEach((item,index,array)=>{
        if(item.entityCode == entity.value){
          item.childArr.forEach((item,index,arr)=>{
            EntityChildArr.push(JSON.parse(JSON.stringify(item)));
          })
        }
      })
    }

    //选择场景主体触发的函数
    let SceneEntityChildArr = reactive([])
    function selectSceneFn() {
      SceneEntityChild.value = "";
      while(SceneEntityChildArr.length >0){
        SceneEntityChildArr.pop();
      }
      SceneEnitityArr.forEach((item,index,array)=>{
        if(item.entityCode == SceneEntity.value){
          item.childArr.forEach((item,index,arr)=>{
            SceneEntityChildArr.push(JSON.parse(JSON.stringify(item)));
          })
        }

        if(SceneEntity.value == item.entityCode){
          mainLabel.value = item.codeName;
        }
      })

      //根据主体代码获取主体事件列表
      while(SceneEntityEventArr.length >0){
        SceneEntityEventArr.pop();
      }
      while(SceneEntityPropertyArr.length >0){
        SceneEntityPropertyArr.pop();
      }
      const reqEventBody = {
        "entityCode":SceneEntity.value,
        "entityType":null
      }
      postRequest('/channel/channel/getEntityEvent',reqEventBody,(res)=>{
        res.forEach((item,index,arr)=>{
          SceneEntityEventArr.push(JSON.parse(JSON.stringify(item)))
        })
      })

      //根据主体代码获取主体属性列表
      const reqPropertyBody = {
        "entityCode":SceneEntity.value,
        "entityType":null
      }
      postRequest('/channel/channel/getEntityProperty',reqPropertyBody,(res)=>{
        res.forEach((item,index,arr)=>{
          SceneEntityPropertyArr.push(JSON.parse(JSON.stringify(item)));
        })
      })
    }

    let propertyEnglish = ref(null)
    //根据场景主体和子主体获取属性列表和事件列表
    function selectSceneChildFn() {

    SceneEntityChildArr.forEach((item,index,array)=>{
      if(SceneEntityChild.value == item.entityType){
        childLabel.value = item.typeName;
      }
    })
      while(SceneEntityEventArr.length >0){
        SceneEntityEventArr.pop();
      }
      while(SceneEntityPropertyArr.length >0){
        SceneEntityPropertyArr.pop();
      }

      const reqEventBody = {
        "entityCode":SceneEntity.value,
        "entityType":SceneEntityChild.value
      }
      postRequest('/channel/channel/getEntityEvent',reqEventBody,(res)=>{
        res.forEach((item,index,arr)=>{
          SceneEntityEventArr.push(JSON.parse(JSON.stringify(item)))
        })
      })
      //-------------------------------------------------------------------------------------------------
      const reqPropertyBody = {
       // "groupEntityCode":companyId.value,
        "entityCode":SceneEntity.value,
        "entityType":SceneEntityChild.value
      }
      postRequest('/channel/channel/getEntityProperty',reqPropertyBody,(res)=>{
        console.log("resxpa3",res);
        if(res.length>0){
          propertyEnglish.value = res[0].propertyEnglish;
          const requestInterface = {
            entityCode: SceneEntity.value,
            entityType: SceneEntityChild.value,
            eventCode: "001",
            propertyCode: propertyEnglish.value
          }
          postRequest('channel/channel/getPropertyInterface',requestInterface,(res)=>{
            if(res && res.data !== null){
              postRequest(res.data.interfaceEnglish,{companyId:companyId.value},(res)=>{
                res.forEach((item,index,array)=>{
                  SceneEntityPropertyArr.push(JSON.parse(JSON.stringify(item)))
                })
              })
            }
          })
        }
      })
    }


    //获取权限事项列表
    let AstridTasks = reactive([])

    function getObjectType() {
      return new Promise<void>((resolve, reject) => {
        getRequest('/channel/channel/getObjectType', (res) => {
          res.forEach((item, index, arr) => {
            AstridTasks.push(item);
          })
          resolve()
        })
      })
    }

    //公用函数，专门用来处理请求体数据结构的
    let requestBody = reactive([]);
    function dealBody(entity,entityChild,role) {
      let codeName = ''
      let typeName = ''
      if(!!entity){
        SceneEnitityArr.forEach((item,index,array)=>{
          if(item.entityCode == entity){
            codeName = item.codeName
          }
        })
        EntityArr.forEach((item,index,array)=>{
          if(item.entityCode == entity){
            item.childArr.forEach((item,index,arr)=>{
              if(item.entityType == entityChild){
                typeName = item.typeName;
              }
            })
          }
        })
        if(entity == '102'){
          requestBody.push({
            "entityCode":entity,
            "codeName":codeName,
            "entityType":entityChild,
            "typeName":typeName,
            "eventCode":null,
            "eventName":null,
            "propertyEnglish":'roleType',
            "propertyChinese":'',
            "propertyValue":role,
            "propertyCondition":null,
            "companyId":companyId.value
          })
        }else{
          requestBody.push({
            "entityCode":entity,
            "codeName":codeName,
            "entityType":entityChild,
            "typeName":typeName,
            "eventCode":null,
            "eventName":null,
            "propertyEnglish":'',
            "propertyChinese":'',
            "propertyValue":role,
            "propertyCondition":null,
            "companyId":companyId.value
          })
        }
      }
    }

    let SceneCode = ref(null)
    let TreeArray = reactive([])
    //点击查询按钮，查询主体属性，查询场景代码，查询订阅属性
    async function queryEntityMessage() {
      while(requestBody.length > 0){
        requestBody.pop()
      }
      //给当事主体赋值
      while(groupEntity.value.length > 0){
        groupEntity.value.pop()
      }
      while(EntityPropertyOptions.length > 0){
        EntityPropertyOptions.pop()
      }
      //给当事子主体赋值
      while(groupChildEntity.value.length > 0){
        groupChildEntity.value.pop()
      }
      while(EntityChildPropertyOptions.length > 0){
        EntityChildPropertyOptions.pop()
      }
        EntityArr.forEach((item,index,array)=>{
          if(item.entityCode == entity.value){
            groupEntity.value.push(item.entityCode)
            EntityPropertyOptions.push({
              label:item.codeName,
              value:item.entityCode
            })
          }
        })
        EntityChildArr.forEach((item,index,array)=>{
          if(item.entityType == entityChild.value){
            groupChildEntity.value.push(item.entityType)
            EntityChildPropertyOptions.push({
              label:item.typeName,
              value:item.entityType
            })
          }
        })
      while(group.value.length > 0){
        group.value.pop()
      }
      while(PropertyOptions.length > 0){
        PropertyOptions.pop()
      }
      while(Authoritygroup.value.length > 0){
        Authoritygroup.value.pop()
      }
      while(AuthorityPropertyOptions.length > 0){
        AuthorityPropertyOptions.pop()
      }

      let step1 = () => {
        return new Promise<void>((resolve, reject) => {
          //通过当事主体当事子主体查询主体属性
          if (AstridTasksValue.value == '104') {
            const reqAllEventBody = {
              "entityCode": entity.value,
              "entityType": entityChild.value
            }
            postRequest('/channel/channel/getEntityEvent', reqAllEventBody, (res) => {
              resolve()
              res.forEach((item, index, array) => {
                PropertyOptions.push({
                  label: item.eventName,
                  value: item.eventCode
                })
              })
            })
          } else if (AstridTasksValue.value == '301') {
            const requestAuthority = {
              "entityCode": entity.value,
              "entityType": entityChild.value
            }
            getRequest('/route/route/getTheirRelation', (res) => {
              resolve()
              res.forEach((item, index, array) => {
                AuthorityPropertyOptions.push({
                  label: item.otherEntityTypeName,
                  value: item.relationCode,
                  otherEntityCode: item.otherEntityCode,
                  otherEntityCodeName: item.otherEntityCodeName,
                  otherEntityType: item.otherEntityType,
                  otherEntityTypeName: item.otherEntityTypeName
                })
              })
            }, requestAuthority)
          } else if (AstridTasksValue.value == '120') {
            const reqAllPropertyBody = {
              "entityCode": entity.value,
              "entityType": entityChild.value
            }
            postRequest('/channel/channel/queryPropertyDic', reqAllPropertyBody, (res) => {
              resolve()
              swapProperty = res
              res.forEach((item, index, array) => {
                PropertyOptions.push({
                  label: item.name,
                  value: item.propertyCode + item.valueCode,
                  propertyType: 'char',
                  propertyLength: '32'
                })
              })



            })



          } else {
            const reqAllPropertyBody = {
              "groupEntityCode": companyId.value,
              "entityCode": entity.value,
              "entityType": entityChild.value
            }
            postRequest('/channel/channel/getEntityProperty', reqAllPropertyBody, (res) => {
              resolve()
              console.log("resall", res);
              res.forEach((item, index, array) => {
                PropertyOptions.push({
                  label: item.propertyChinese,
                  value: item.propertyEnglish,
                  propertyType: item.propertyType,
                  propertyLength: item.propertyLength
                })
              })
              console.log('PropertyOptions', PropertyOptions);
            })
          }
          dealBody(SceneEntity.value, SceneEntityChild.value, Property.value);
          dealBody(SceneEntity1.value, SceneEntityChild1.value, Property1.value);
          dealBody(SceneEntity2.value, SceneEntityChild2.value, Property2.value);
        })
      }
      
      //查询场景代码
      let searchSceneCode = async () => {
        return new Promise<void>((resolve, reject) => {
          postRequest('/channel/channel/getSceneCode', requestBody, (res) => {
            SceneCode.value = res;
            let requestAuthorityBody
            //获取已订阅权限
            if (AstridTasksValue.value == '104') {
              requestAuthorityBody = {
                "companyId": companyId.value,
                "groupEntityCode": "101",
                "chainHead": "123454",
                "entityCode": entity.value,
                "codeName": "",
                "entityType": entityChild.value,
                "typeName": null,
                "theirEventCode": "007",
                "theirEventName": "载入",
                "objectCodeType": "104",
                "operateEntity": entity.value + entityChild.value,
                "objectCodeName": "",
                "sceneCode": SceneCode.value,
                "sceneCodeType": "",
                "sceneCodeName": "渠道+用户+角色+主体",
                "chainTail": "123455"
              }
            } else if (AstridTasksValue.value == '120') {
              requestAuthorityBody = {
                "companyId": userData.companyId,
                "entityCode": entity.value,
                "entityType": entityChild.value,
                "objectCodeType": "120",
                "sceneCode": SceneCode.value
              }
            } else {
              const oldTempCode = ['101', '102', '103', '104', '002', '003', '301', '107']
              let resolveValue = AstridTasksValue.value;

              // if (!oldTempCode.includes(resolveValue)) {
              //   resolveValue = '003'
              // }
              requestAuthorityBody = {
                "companyId": companyId.value,
                "groupEntityCode": "101",
                "chainHead": "123454",
                "entityCode": entity.value,
                "codeName": "法律",
                "entityType": entityChild.value,
                "typeName": null,
                "theirEventCode": "007",
                "theirEventName": "载入",
                "objectCodeType": resolveValue,
                "objectCodeName": "",
                "sceneCode": SceneCode.value,
                "sceneCodeType": "",
                "sceneCodeName": "渠道+用户+角色+主体",
                "chainTail": "123455"
              }
            }
            postRequest('/channel/channel/getAuthority', requestAuthorityBody, (res) => {
              if(res==null){
                return resolve()
              }
              res.forEach((item, index, array) => {
                if (AstridTasksValue.value == '104') {
                  group.value.push(item.eventCode)
                } else if (AstridTasksValue.value == '301') {
                  Authoritygroup.value.push(item.relationCode)
                } else if (AstridTasksValue.value == '120') {
                  group.value.push(item.propertyCode + item.valueCode)
                } else {
                  group.value.push(item.propertyEnglish)
                }
              })
              resolve()
            })

          })
        })
      }

      await step1()
      await searchSceneCode()
    }

    function searchEntityName() {
      let a = ''
      EntityArr.forEach((item,index,array)=>{
        if(item.entityCode == entity.value){
          a = item.codeName
        }
      })
      return a
    }

    function searchEntityChildName() {
      let a = ''
      EntityChildArr.forEach((item,index,array)=>{
        if(item.entityType == entityChild.value){
          a = item.typeName
        }
      })
      return a
    }

    //提交订阅信息
    function submitSelectMessage(){
      if(entity.value == null){
        alert('请先选择当事主体');
      }
      else if(SceneCode.value==null){
        alert('请先查询场景代码');
      }else {

        const body = {
          "companyId":companyId.value,
          "entityCode": entity.value,
          "entityType": entityChild.value,
          "objectCodeType": AstridTasksValue.value,
          "sceneCode": SceneCode.value,
          "list": []
        }
        if(AstridTasksValue.value == '104'){
          body['operateEntity'] = entity.value + entityChild.value;
        }

        let entityName = searchEntityName()
        let entityChildName = searchEntityChildName()
        if(AstridTasksValue.value == "301"){
          AuthorityPropertyOptions.forEach((item,index,array)=>{
            let flag = '0'
            if (Authoritygroup.value.includes(item.value)) {
              flag = '1'
            }
            body.list.push({
              "groupEntityCode":"101",
              "otherEntityCode":item.otherEntityCode,
              "otherEntityCodeName":item.otherEntityCodeName,
              "otherEntityType":item.otherEntityType,
              "otherEntityTypeName":item.otherEntityTypeName,
              "relationName": item.label,
              "relationCode": item.value,
              "status": flag
            })
          })
        }else{
          PropertyOptions.forEach((item, index, array) => {
            let flag = '0'
            if (group.value.includes(item.value)) {
              flag = '1'
            }
            if (AstridTasksValue.value == '104') {
              body.list.push({
                "id": "2010101",
                "groupEntityCode": "101",
                "entityCode": entity.value,
                "codeName": entityName,
                "entityType": entityChild.value,
                "typeName": entityChildName,
                "eventCode": item.value,
                "eventName": item.label,
                "companyId": companyId.value,
                "companyName": "万高",
                "gmtCreate": null,
                "gmtModify": null,
                "status": flag
              })
            } else {
              body.list.push({
                "id": "20080112",
                "groupEntityCode": "101",
                "entityCode": entity.value,
                "codeName": entityName,
                "entityType": entityChild.value,
                "typeName": entityChildName,
                "codeNo": "12",
                "propertyEnglish": item.value,
                "propertyChinese": item.label,
                "codeType": null,
                "propertyType": item.propertyType,
                "propertyLength": item.propertyLength,
                "gmtCreate": "2021-10-12T12:59:47.000+00:00",
                "gmtModify": "2021-10-12T12:59:47.000+00:00",
                "status": flag
              })
            }
          })
        }
        if (AstridTasksValue.value == '120') {
          body.list = []

          group.value.forEach(x => {
            swapProperty.forEach(y => {
              if (y.propertyCode + y.valueCode === x) {
                y.status = '1'
                body.list.push(y)
              }
            })
          })
        }
        postRequest('/channel/channel/updateAuthority', body, (res) => {
          if (res) {
            showNotif()//此处没用，因为前面的封装把res中的状态过滤了，获取不到200
          }
        })
      }
    }


    //提交初始信息
    function submitInitMessage() {
      return new Promise<void>((resolve, reject) => {
        //数据准备
        let entityName = searchEntityName();
        let entityChildName = searchEntityChildName();
        let requestAuthorityBody;

        console.log("初始化开始entityName：", entityName);

        if (entity.value == null) {
          alert('请先选择当事主体');
        }
        else if (SceneCode.value == null) {
          alert('请先查询场景代码');
        } else {

          //主体属性相关初始处理


          AstridTasksValue.value = '104';
          console.log("AstridTasksValue104的呀", AstridTasksValue.value);

          const body = {
            "companyId": companyId.value,
            "entityCode": entity.value,
            "entityType": entityChild.value,
            "objectCodeType": AstridTasksValue.value,
            "sceneCode": SceneCode.value,
            "list": []
          }

          console.log("body", body);


          //根据主体代码获取主体事件列表

          const reqAllEventBody = {
            "entityCode": entity.value,
            "entityType": entityChild.value
          }
          postRequest('/channel/channel/getEntityEvent', reqAllEventBody, (res) => {
            res.forEach((item, index, array) => {
              // PropertyOptions.push({
              //   label:item.eventName,
              //   value:item.eventCode
              // })
              let flag = '1'
              body.list.push({
                "id": "2010101",
                "groupEntityCode": "101",
                "entityCode": entity.value,
                "codeName": entityName,
                "entityType": entityChild.value,
                "typeName": entityChildName,
                "eventCode": item.eventCode,
                "eventName": item.eventName,
                "companyId": companyId.value,
                "companyName": "商讯",
                "gmtCreate": null,
                "gmtModify": null,
                "status": flag
              })


            })




            postRequest('/channel/channel/updateAuthority', body, (res) => {

              console.log("权限设置成功", AstridTasksValue.value);


              //增加关系处理逻辑

              AstridTasksValue.value = '301';

              requestAuthorityBody = {
                "companyId": companyId.value,
                "groupEntityCode": "101",
                "chainHead": "123454",
                "entityCode": entity.value,
                "codeName": "法律",
                "entityType": entityChild.value,
                "typeName": null,
                "theirEventCode": "007",
                "theirEventName": "载入",
                "objectCodeType": AstridTasksValue.value,
                "objectCodeName": "",
                "sceneCode": SceneCode.value,
                "sceneCodeType": "",
                "sceneCodeName": "渠道+用户+角色+主体",
                "chainTail": "123455"
              }

              postRequest('/channel/channel/getAuthority', requestAuthorityBody, (res) => {



                console.log("AstridTasksValue", AstridTasksValue.value);

                const body301 = {
                  "companyId": companyId.value,
                  "entityCode": entity.value,
                  "entityType": entityChild.value,
                  "objectCodeType": AstridTasksValue.value,
                  "sceneCode": SceneCode.value,
                  "list": []
                }

                console.log("body301", body301);



                const requestAuthority = {
                  "entityCode": entity.value,
                  "entityType": entityChild.value
                }
                getRequest('/route/route/getTheirRelation', (res) => {
                  res.forEach((item, index, array) => {


                    let flag = '1'
                    body301.list.push({
                      "groupEntityCode": "101",
                      "otherEntityCode": item.otherEntityCode,
                      "otherEntityCodeName": item.otherEntityCodeName,
                      "otherEntityType": item.otherEntityType,
                      "otherEntityTypeName": item.otherEntityTypeName,
                      "relationName": item.otherEntityTypeName,
                      "relationCode": item.relationCode,
                      "status": flag
                    })


                  })

                  postRequest('/channel/channel/updateAuthority', body301, (res) => {
                    console.log("权限设置成功", AstridTasksValue.value);
                    resolve()
                  })
                }, requestAuthority)
              })
            })
          })
          //主体事情
        }
      })
    }



    //提交初始信息
    function submitInitMessage1() {
      return new Promise<void>((resolve, reject) => {
        //数据准备
        let entityName = searchEntityName();
        let entityChildName = searchEntityChildName();
        let requestAuthorityBody;

        console.log("初始化开始entityName：", entityName);

        if (entity.value == null) {
          alert('请先选择当事主体');
        }
        else if (SceneCode.value == null) {
          alert('请先查询场景代码');
        } else {

          //主体属性相关初始处理


          AstridTasksValue.value = '102';
          console.log("AstridTasksValue", AstridTasksValue.value);

          const body = {
            "companyId": companyId.value,
            "entityCode": entity.value,
            "entityType": entityChild.value,
            "objectCodeType": AstridTasksValue.value,
            "sceneCode": SceneCode.value,
            "list": []
          }

          console.log("body", body);


          //根据主体代码获取主体属性列表
          const reqPropertyBody = {
            "groupEntityCode": companyId.value,
            "entityCode": entity.value,
            "entityType": entityChild.value,
          }

          console.log("reqPropertyBody", reqPropertyBody);

          postRequest('/channel/channel/getEntityProperty', reqPropertyBody, (res) => {
            console.log("res", res);
            res.forEach((item, index, arr) => {

              // SceneEntityPropertyArr1.push(JSON.parse(JSON.stringify(item)));

              let flag = '1'
              body.list.push({
                "id": "20080112",
                "groupEntityCode": "101",
                "entityCode": entity.value,
                "codeName": entityName,
                "entityType": entityChild.value,
                "typeName": entityChildName,
                "codeNo": "12",
                "propertyEnglish": item.propertyEnglish,
                "propertyChinese": item.propertyChinese,
                "codeType": null,
                "propertyType": item.propertyType,
                "propertyLength": item.propertyLength,
                "gmtCreate": "2021-10-12T12:59:47.000+00:00",
                "gmtModify": "2021-10-12T12:59:47.000+00:00",
                "status": flag
              })



            })


            postRequest('/channel/channel/updateAuthority', body, (res) => {

              console.log("权限设置成功", AstridTasksValue.value);

              AstridTasksValue.value = '002';

              requestAuthorityBody = {
                "companyId": companyId.value,
                "groupEntityCode": "101",
                "chainHead": "123454",
                "entityCode": entity.value,
                "codeName": "法律",
                "entityType": entityChild.value,
                "typeName": null,
                "theirEventCode": "007",
                "theirEventName": "载入",
                "objectCodeType": AstridTasksValue.value,
                "objectCodeName": "",
                "sceneCode": SceneCode.value,
                "sceneCodeType": "",
                "sceneCodeName": "渠道+用户+角色+主体",
                "chainTail": "123455"
              }

              postRequest('/channel/channel/getAuthority', requestAuthorityBody, (res) => {



                console.log("AstridTasksValue002", AstridTasksValue.value);

                const body002 = {
                  "companyId": companyId.value,
                  "entityCode": entity.value,
                  "entityType": entityChild.value,
                  "objectCodeType": AstridTasksValue.value,
                  "sceneCode": SceneCode.value,
                  "list": []
                }

                console.log("body002", body002);


                //根据主体代码获取主体属性列表
                const reqPropertyBody002 = {
                  "groupEntityCode": companyId.value,
                  "entityCode": entity.value,
                  "entityType": entityChild.value,
                }

                postRequest('/channel/channel/getEntityProperty', reqPropertyBody002, (res) => {
                  console.log("res002", res);
                  res.forEach((item, index, arr) => {

                    // SceneEntityPropertyArr1.push(JSON.parse(JSON.stringify(item)));

                    let flag = '1'
                    body002.list.push({
                      "id": "20080112",
                      "groupEntityCode": "101",
                      "entityCode": entity.value,
                      "codeName": entityName,
                      "entityType": entityChild.value,
                      "typeName": entityChildName,
                      "codeNo": "12",
                      "propertyEnglish": item.propertyEnglish,
                      "propertyChinese": item.propertyChinese,
                      "codeType": null,
                      "propertyType": item.propertyType,
                      "propertyLength": item.propertyLength,
                      "gmtCreate": "2021-10-12T12:59:47.000+00:00",
                      "gmtModify": "2021-10-12T12:59:47.000+00:00",
                      "status": flag
                    })



                  })


                  postRequest('/channel/channel/updateAuthority', body002, (res) => {

                    console.log("权限设置成功002", AstridTasksValue.value);



                    AstridTasksValue.value = '003';

                    requestAuthorityBody = {
                      "companyId": companyId.value,
                      "groupEntityCode": "101",
                      "chainHead": "123454",
                      "entityCode": entity.value,
                      "codeName": "法律",
                      "entityType": entityChild.value,
                      "typeName": null,
                      "theirEventCode": "007",
                      "theirEventName": "载入",
                      "objectCodeType": AstridTasksValue.value,
                      "objectCodeName": "",
                      "sceneCode": SceneCode.value,
                      "sceneCodeType": "",
                      "sceneCodeName": "渠道+用户+角色+主体",
                      "chainTail": "123455"
                    }

                    postRequest('/channel/channel/getAuthority', requestAuthorityBody, (res) => {



                      console.log("AstridTasksValue003", AstridTasksValue.value);

                      const body003 = {
                        "companyId": companyId.value,
                        "entityCode": entity.value,
                        "entityType": entityChild.value,
                        "objectCodeType": AstridTasksValue.value,
                        "sceneCode": SceneCode.value,
                        "list": []
                      }

                      console.log("body003", body003);


                      //根据主体代码获取主体属性列表
                      const reqPropertyBody003 = {
                        "groupEntityCode": companyId.value,
                        "entityCode": entity.value,
                        "entityType": entityChild.value,
                      }

                      postRequest('/channel/channel/getEntityProperty', reqPropertyBody003, (res) => {
                        console.log("res003", res);
                        res.forEach((item, index, arr) => {

                          let flag = '1'
                          body003.list.push({
                            "id": "20080112",
                            "groupEntityCode": "101",
                            "entityCode": entity.value,
                            "codeName": entityName,
                            "entityType": entityChild.value,
                            "typeName": entityChildName,
                            "codeNo": "12",
                            "propertyEnglish": item.propertyEnglish,
                            "propertyChinese": item.propertyChinese,
                            "codeType": null,
                            "propertyType": item.propertyType,
                            "propertyLength": item.propertyLength,
                            "gmtCreate": "2021-10-12T12:59:47.000+00:00",
                            "gmtModify": "2021-10-12T12:59:47.000+00:00",
                            "status": flag
                          })



                        })


                        postRequest('/channel/channel/updateAuthority', body003, (res) => {

                          console.log("权限设置成功003", AstridTasksValue.value);

                          AstridTasksValue.value = '004';

                          requestAuthorityBody = {
                            "companyId": companyId.value,
                            "groupEntityCode": "101",
                            "chainHead": "123454",
                            "entityCode": entity.value,
                            "codeName": "法律",
                            "entityType": entityChild.value,
                            "typeName": null,
                            "theirEventCode": "007",
                            "theirEventName": "载入",
                            "objectCodeType": AstridTasksValue.value,
                            "objectCodeName": "",
                            "sceneCode": SceneCode.value,
                            "sceneCodeType": "",
                            "sceneCodeName": "渠道+用户+角色+主体",
                            "chainTail": "123455"
                          }

                          postRequest('/channel/channel/getAuthority', requestAuthorityBody, (res) => {



                            console.log("AstridTasksValue004：", AstridTasksValue.value);

                            const body004 = {
                              "companyId": companyId.value,
                              "entityCode": entity.value,
                              "entityType": entityChild.value,
                              "objectCodeType": AstridTasksValue.value,
                              "sceneCode": SceneCode.value,
                              "list": []
                            }

                            console.log("body002", body002);


                            //根据主体代码获取主体属性列表
                            const reqPropertyBody004 = {
                              "groupEntityCode": companyId.value,
                              "entityCode": entity.value,
                              "entityType": entityChild.value,
                            }

                            postRequest('/channel/channel/getEntityProperty', reqPropertyBody004, (res) => {
                              console.log("res004", res);
                              res.forEach((item, index, arr) => {

                                // SceneEntityPropertyArr1.push(JSON.parse(JSON.stringify(item)));

                                let flag = '1'
                                body004.list.push({
                                  "id": "20080112",
                                  "groupEntityCode": "101",
                                  "entityCode": entity.value,
                                  "codeName": entityName,
                                  "entityType": entityChild.value,
                                  "typeName": entityChildName,
                                  "codeNo": "12",
                                  "propertyEnglish": item.propertyEnglish,
                                  "propertyChinese": item.propertyChinese,
                                  "codeType": null,
                                  "propertyType": item.propertyType,
                                  "propertyLength": item.propertyLength,
                                  "gmtCreate": "2021-10-12T12:59:47.000+00:00",
                                  "gmtModify": "2021-10-12T12:59:47.000+00:00",
                                  "status": flag
                                })



                              })


                              postRequest('/channel/channel/updateAuthority', body004, (res) => {

                                resolve()

                                console.log("权限设置成功004", AstridTasksValue.value);

                                if (res) {
                                  showNotif()//此处没用，因为前面的封装把res中的状态过滤了，获取不到200
                                }

                                //
                                // AstridTasksValue.value = '101';
                                // requestAuthorityBody = {
                                //   "companyId":companyId.value,
                                //   "groupEntityCode":"101",
                                //   "chainHead":"123454",
                                //   "entityCode":"001",
                                //   "codeName":"法律",
                                //   "entityType":"01",
                                //   "typeName":null,
                                //   "theirEventCode":"007",
                                //   "theirEventName":"载入",
                                //   "objectCodeType":AstridTasksValue.value,
                                //   "objectCodeName":"",
                                //   "sceneCode":SceneCode.value,
                                //   "sceneCodeType":"",
                                //   "sceneCodeName":"渠道+用户+角色+主体",
                                //   "chainTail":"123455"
                                // }
                                //
                                // postRequest('/channel/channel/getAuthority',requestAuthorityBody,(res)=>{
                                //
                                //
                                //
                                //   console.log("AstridTasksValue101：",AstridTasksValue.value);
                                //
                                //   const body101 = {
                                //     "companyId":companyId.value,
                                //     "entityCode": "001",
                                //     "entityType": "01",
                                //     "objectCodeType": AstridTasksValue.value,
                                //     "sceneCode": SceneCode.value,
                                //     "list": []
                                //   }
                                //
                                //   console.log("body101",body101);
                                //
                                //
                                //
                                //       // SceneEntityPropertyArr1.push(JSON.parse(JSON.stringify(item)));
                                //
                                //       let flag = '1'
                                //       body101.list.push({
                                //         "id": "20080112",
                                //         "groupEntityCode": "101",
                                //         "entityCode": "001",
                                //         "codeName": "操作首页",
                                //         "entityType": "01",
                                //         "typeName": "首页菜单",
                                //         "codeNo": "12",
                                //         "propertyEnglish": entity.value,
                                //         "propertyChinese": entityName,
                                //         "codeType": null,
                                //         "propertyType": null,
                                //         "propertyLength": null,
                                //         "gmtCreate": "2021-10-12T12:59:47.000+00:00",
                                //         "gmtModify": "2021-10-12T12:59:47.000+00:00",
                                //         "status": flag
                                //       })
                                //
                                //
                                //
                                //     postRequest('/channel/channel/updateAuthority', body101, (res) => {
                                //
                                //       console.log("权限设置成功",AstridTasksValue.value);
                                //
                                //
                                //
                                //
                                //
                                //
                                //
                                //     })
                                //
                                // })
                                //101结束





                              })
                            })
                          })
                          //004结束






                        })
                      })

                    })

                    //003结束



                    if (res) {
                      showNotif()//此处没用，因为前面的封装把res中的状态过滤了，获取不到200
                    }

                  })
                })
              })
              //002结束






              if (res) {
                showNotif()//此处没用，因为前面的封装把res中的状态过滤了，获取不到200
              }


            })
          })

          //102结束




        }
      })
    }


    //提交初始信息
    function submitInitMessage0(){



      //数据准备
      let entityName = searchEntityName();
      let entityChildName = searchEntityChildName();

      console.log("初始化开始entityName：",entityName);

      if(entity.value == null){
        alert('请先选择当事主体');
      }
      else if(SceneCode.value==null){
        alert('请先查询场景代码');
      }else {

        //主体属性相关初始处理


        AstridTasksValue.value = '102';


        const body = {
          "companyId":companyId.value,
          "entityCode": entity.value,
          "entityType": entityChild.value,
          "objectCodeType": AstridTasksValue.value,
          "sceneCode": SceneCode.value,
          "list": []
        }

        //根据主体代码获取主体属性列表
        const reqPropertyBody = {
         // "groupEntityCode":companyId.value,
          "entityCode":entity.value,
          "entityType":entityChild.value,
        }

        postRequest('/channel/channel/getEntityProperty',reqPropertyBody,(res)=>{
          console.log("res",res);
          res.forEach((item,index,arr)=>{

            // SceneEntityPropertyArr1.push(JSON.parse(JSON.stringify(item)));

            let flag = '1'
            body.list.push({
              "id": "20080112",
              "groupEntityCode": "101",
              "entityCode": entity.value,
              "codeName": entityName,
              "entityType": entityChild.value,
              "typeName": entityChildName,
              "codeNo": "12",
              "propertyEnglish": item.propertyEnglish,
              "propertyChinese": item.propertyChinese,
              "codeType": null,
              "propertyType": item.propertyType,
              "propertyLength": item.propertyLength,
              "gmtCreate": "2021-10-12T12:59:47.000+00:00",
              "gmtModify": "2021-10-12T12:59:47.000+00:00",
              "status": flag
            })



          })


          postRequest('/channel/channel/updateAuthority', body, (res) => {

            console.log("权限设置成功",AstridTasksValue.value);


            //主体修改
            AstridTasksValue.value = '003';

            const body003 = {
              "companyId":companyId.value,
              "entityCode": entity.value,
              "entityType": entityChild.value,
              "objectCodeType": AstridTasksValue.value,
              "sceneCode": SceneCode.value,
              "list": []
            }

            //根据主体代码获取主体属性列表
            const reqPropertyBody003 = {
            // "groupEntityCode":companyId.value,
              "entityCode":entity.value,
              "entityType":entityChild.value,
            }

            postRequest('/channel/channel/getEntityProperty',reqPropertyBody003,(res)=>{
              console.log("res003",res);
              res.forEach((item,index,arr)=>{

                // SceneEntityPropertyArr1.push(JSON.parse(JSON.stringify(item)));

                let flag = '1'
                body003.list.push({
                  "id": "20080112",
                  "groupEntityCode": "101",
                  "entityCode": entity.value,
                  "codeName": entityName,
                  "entityType": entityChild.value,
                  "typeName": entityChildName,
                  "codeNo": "12",
                  "propertyEnglish": item.propertyEnglish,
                  "propertyChinese": item.propertyChinese,
                  "codeType": null,
                  "propertyType": item.propertyType,
                  "propertyLength": item.propertyLength,
                  "gmtCreate": "2021-10-12T12:59:47.000+00:00",
                  "gmtModify": "2021-10-12T12:59:47.000+00:00",
                  "status": flag
                })



              })

              console.log("body003",body003);
              postRequest('/channel/channel/updateAuthority', body003, (res) => {

                console.log("权限设置成功",AstridTasksValue.value);


                //主体删除
                AstridTasksValue.value = '004';

                const body004 = {
                  "companyId":companyId.value,
                  "entityCode": entity.value,
                  "entityType": entityChild.value,
                  "objectCodeType": AstridTasksValue.value,
                  "sceneCode": SceneCode.value,
                  "list": []
                }

                //根据主体代码获取主体属性列表
                const reqPropertyBody004 = {
                // "groupEntityCode":companyId.value,
                  "entityCode":entity.value,
                  "entityType":entityChild.value,
                }

                postRequest('/channel/channel/getEntityProperty',reqPropertyBody004,(res)=>{
                  console.log("res004",res);
                  res.forEach((item,index,arr)=>{

                    // SceneEntityPropertyArr1.push(JSON.parse(JSON.stringify(item)));

                    let flag = '1'
                    body004.list.push({
                      "id": "20080112",
                      "groupEntityCode": "101",
                      "entityCode": entity.value,
                      "codeName": entityName,
                      "entityType": entityChild.value,
                      "typeName": entityChildName,
                      "codeNo": "12",
                      "propertyEnglish": item.propertyEnglish,
                      "propertyChinese": item.propertyChinese,
                      "codeType": null,
                      "propertyType": item.propertyType,
                      "propertyLength": item.propertyLength,
                      "gmtCreate": "2021-10-12T12:59:47.000+00:00",
                      "gmtModify": "2021-10-12T12:59:47.000+00:00",
                      "status": flag
                    })



                  })


                  postRequest('/channel/channel/updateAuthority', body004, (res) => {

                    console.log("权限设置成功",AstridTasksValue.value);

                    //主体删除
                    AstridTasksValue.value = '002';

                    const body002 = {
                      "companyId":companyId.value,
                      "entityCode": entity.value,
                      "entityType": entityChild.value,
                      "objectCodeType": AstridTasksValue.value,
                      "sceneCode": SceneCode.value,
                      "list": []
                    }


                    //根据主体代码获取主体属性列表
                    const reqPropertyBody002 = {
                     //  "groupEntityCode":companyId.value,
                      "entityCode":entity.value,
                      "entityType":entityChild.value,
                    }

                    postRequest('/channel/channel/getEntityProperty',reqPropertyBody002,(res)=>{
                      console.log("res002",res);
                      res.forEach((item,index,arr)=>{

                        // SceneEntityPropertyArr1.push(JSON.parse(JSON.stringify(item)));

                        let flag = '1'
                        body002.list.push({
                          "id": "20080112",
                          "groupEntityCode": "101",
                          "entityCode": entity.value,
                          "codeName": entityName,
                          "entityType": entityChild.value,
                          "typeName": entityChildName,
                          "codeNo": "12",
                          "propertyEnglish": item.propertyEnglish,
                          "propertyChinese": item.propertyChinese,
                          "codeType": null,
                          "propertyType": item.propertyType,
                          "propertyLength": item.propertyLength,
                          "gmtCreate": "2021-10-12T12:59:47.000+00:00",
                          "gmtModify": "2021-10-12T12:59:47.000+00:00",
                          "status": flag
                        })



                      })


                      postRequest('/channel/channel/updateAuthority', body002, (res) => {

                        console.log("权限设置成功",AstridTasksValue.value);


                        //002结尾
                      })
                    })



                    //004结尾
                  })
                })


                //003结尾

              })
            })


            if (res) {
              showNotif()//此处没用，因为前面的封装把res中的状态过滤了，获取不到200
            }

            //102结尾
          })
        })






      }
    }



    function showNotif() {
      $q.notify({
        message: '恭喜，权限订阅信息提交成功',
        color: 'purple',
        position:'top',
        badgeColor:'#d4bad4cc',
        timeout:1000
      })
    }
    let ticked = reactive([])
    let expanded = reactive([])
    onMounted(()=>{

    })

    //批量 开始
    let canUseBatch = ref(0)

    async function batch() {
      function waitSeconds(n){
        return new Promise<void>((resolve, reject) => {
          setTimeout(() => {
            resolve()
          }, n*1000);
        })
      }

      SceneEntity.value = '101'
      SceneEntityChild.value = '01'
      SceneEntity1.value = '102'
      SceneEntityChild1.value = '02'
      Property1.value = '04'

      for(let i=0;i<EntityArr.length;i++){
        for(let i1=0;i1<EntityArr[i].childArr.length;i1++){
          let current = EntityArr[i].childArr[i1]
          if(current.entityCode=='001')continue
          entity.value = current.entityCode
          entityChild.value = current.entityType
          console.log(entity.value,entityChild.value)
          
          //主体操作
          AstridTasksValue.value = '104'
          try {
            await queryEntityMessage()
          } catch (error) {
            console.log('aaaaaaaa',error)
          }
          try {
            await submitInitMessage()
          } catch (error) {
            console.log('bbbbbbbb',error)
          }
          

          // //主体首页
          AstridTasksValue.value = '102'
          try {
            await queryEntityMessage()
          } catch (error) {
            console.log('cccccccc',error)
          }
          try {
            await submitInitMessage1()
          } catch (error) {
            console.log('ddddddd',error)
          }
          
          
        }
      }

      canUseBatch.value++

      // console.log('batch',AstridTasksValue.value)

    }
    //批量 结束

    return {
      canUseBatch,
      batch,
      ticked,
      expanded,
      TreeArray,
      EntityArr,
      getCompanyEntity,
      entity,
      entityChild,
      EntityChildArr,
      selectFn,
      model,
      options,
      AstridTasks,
      AstridTasksValue,
      SceneEnitityArr,
      SceneEntity,
      selectSceneFn,
      SceneEntityChildArr,
      SceneEntityChild,
      selectSceneChildFn,
      SceneEntityEventArr,
      SceneEntityPropertyArr,
      Event,
      Property,
      mainEntity,
      group,
      mainLabel,
      childLabel,
      PropertyOptions,
      queryEntityMessage,
      groupEntity,
      EntityPropertyOptions,
      groupChildEntity,
      EntityChildPropertyOptions,
      submitSelectMessage,
      submitInitMessage,
      submitInitMessage1,
      submitInitMessage0,
      showNotif,
      SceneEntity1,
      SceneEntity2,
      SceneEnitityArr1,
      SceneEnitityArr2,
      SceneEntityChild1,
      SceneEntityChild2,
      SceneEntityChildArr1,
      SceneEntityChildArr2,
      selectSceneFn1,
      selectSceneFn2,
      selectSceneChildFn1,
      selectSceneChildFn2,
      Event1,
      Event2,
      Property1,
      Property2,
      SceneEntityEventArr1,
      SceneEntityEventArr2,
      SceneEntityPropertyArr1,
      SceneEntityPropertyArr2,
      SceneCode,
      dealBody,
      requestBody,
      searchEntityName,
      searchEntityChildName,
      Authoritygroup,
      AuthorityPropertyOptions,
      companyId,
      getInformation
    }
  }
};
</script>

<style scoped lang='sass'>
.row > div
  padding: 10px 15px
  background: #ffffff

.row + .row
  margin-top: 1rem
.inner
  font-size: 20px
.btn-fixed-width
  width: 100px
</style>
